﻿using System;
using System.Globalization;
using Ipmce.RemoteVoting.Backend.SmsGateway.Exceptions;

namespace Ipmce.RemoteVoting.Backend.SmsGateway.Processing
{
	class VoterSmsInfoParser : IVoterSmsInfoParser
	{
		public VoterSmsInfo Parse(string smsText)
		{
			var data = smsText.Split(' ');
			if (data.Length != 2)
			{
				throw new InvalidSmsTextFormatException();
			}
			DateTime birhday;
		    var culture = new CultureInfo("ru-ru");
			if (!DateTime.TryParse(data[1], culture, DateTimeStyles.None, out birhday))
			{
				throw new InvalidSmsTextFormatException();
			}
			return new VoterSmsInfo
			             	{
			             		PassportNumber = data[0],
								Birthdate = birhday
			             	};
		}
	}
}